617B - Chocolate - CodeForces Solution


combinatorics *1300

Please click on ads to support us..

Python Code:

n=int(input())
l=list(map(int,input().split()))
s=0
k=1
if 1 not in l: print(0)
else:
    for i in range(l.index(1),len(l)):
        if l[i]==0:
            s+=1
        else:
            k*=s+1
            s=0
    print(k)

C++ Code:

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define lld long double
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define loop(i,a,b) for(int i=a; i<b; i++)
#define bloop(i,a,b) for(int i=a; i>=b; i--)
#define tc(t) int t; cin>>t; while(t--)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define vpi vector<pi>
#define all(a) a.begin(),a.end()
#define rall(a) a.end(),a.begin()

#define py cout<<"YES\n";
#define pn cout<<"NO\n";
#define PI 3.141592653589793238
#define mod (int) 1000000007
#define infinity (int) (1e18)


bool isPerfectSquare(long double x)
{
    // Find floating point value of
    // square root of x.
    if (x >= 0) {
  long long sr = sqrt(x);
        // if product of square root
        //is equal, then
        // return T/F
        return (sr * sr == x);
    }
    // else return false if n<0
       return false;
}


bool prime (long long int n) {
  bool prime = 1;
  if (n == 1) {
      return 0;
  }
  else {
      for (long long int i = 2; i <= n/2 ; i++) {
          if (n % i == 0) {
              prime = 0;
              break ;
          } 
      }
        return prime;
  }
}


// precompute number is prime or not using seive 
// const int k=1e7;
// vector<bool> v(k,1);

// // paste it inside main fun|
// v[0]=v[1]=false;           <-from here
//  for(int i=2;i<k;i++){
//     if(v[i]==true)
//     for(int j=2*i; j<k; j=j+i){
//         if(v[j]==true)
//         v[j]=false;
//     }
//  }

int main(){
 int n;
 cin>>n;
 ll ans;

  vi arr(n);
  int zer=1;
  for0(i,n){
    cin>>arr[i];
    if(arr[i]==1)
    zer=0;
  }

  if(zer==1){
    ans=0;
  }
  else{
  int c=0;
   ans=1;
  int flag=0;
  for0(i,n){
    if(arr[i]==0  && flag==1){
      c++;
    }
    else if(arr[i]==1){
        flag=1;
        ans*= (c+1);
        c=0;
    }
  }
  }

  cout<<ans<<endl;
return 0;
}


Comments

Submit
0 Comments
More Questions

1177B - Digits Sequence (Hard Edition)
1155B - Game with Telephone Numbers
1284A - New Year and Naming
863B - Kayaking
1395B - Boboniu Plays Chess
1475D - Cleaning the Phone
617B - Chocolate
1051B - Relatively Prime Pairs
95B - Lucky Numbers
1692D - The Clock
1553D - Backspace
1670D - Very Suspicious
1141B - Maximal Continuous Rest
1341A - Nastya and Rice
1133A - Middle of the Contest
385A - Bear and Raspberry
1311B - WeirdSort
1713F - Lost Array
236B - Easy Number Challenge
275A - Lights Out
147A - Punctuation
253A - Boys and Girls
1327E - Count The Blocks
984A - Game
12B - Correct Solution
1355B - Young Explorers
485A - Factory
628A - Tennis Tournament
1436B - Prime Square
1707B - Difference Array